<template>
  <div>
    <!-- svg精灵图 -->
    <svg-icon v-if="isFull" class="myicon" icon-class="exit-fullscreen" @click="toggle" />
    <svg-icon v-else class="myicon" icon-class="fullscreen" @click="toggle" />
  </div>
</template>

<script>
// 下载 => 引入 => 使用
import ScreenFull from 'screenfull'
export default {
  data() {
    return {
      isFull: false // 默认不全屏
    }
  },
  methods: {
    toggle() {
      if (!ScreenFull.isEnabled) {
        // 这个浏览器是真的不支持全屏
        this.$message.error('兄弟, 换个浏览器吧..')
        return
      }

      ScreenFull.toggle()
      this.isFull = !this.isFull
    }
  }
}
</script>

<style lang='scss' scoped>
.myicon {
  width: 20px;
  height: 20px;
  fill: white;
  cursor: pointer;
}
</style>
